/**
 * 更新自定义顶部导航栏的高度
 */
/**
 * 更新自定义顶部导航栏的高度
 */
function updateCustomBarInfo() {
	return new Promise((resolve, reject) => {
		try {
			// 使用新的 API 替代 uni.getSystemInfo
			const windowInfo = uni.getWindowInfo()
			const appBaseInfo = uni.getAppBaseInfo()

			let statusBarHeight = 0
			let customBarHeight = 0

			// #ifndef MP
			statusBarHeight = windowInfo.statusBarHeight
			if (appBaseInfo.platform == 'android') {
				customBarHeight = windowInfo.statusBarHeight + 50
			} else {
				customBarHeight = windowInfo.statusBarHeight + 45
			};
			// #endif

			// #ifdef MP-WEIXIN
			statusBarHeight = windowInfo.statusBarHeight
			let custom = wx.getMenuButtonBoundingClientRect()
			customBarHeight = custom.bottom + ((custom.top - windowInfo.statusBarHeight) <= 4 ? (custom
				.top - windowInfo.statusBarHeight) + 4 : (custom.top - windowInfo.statusBarHeight))
			// #endif		

			// #ifdef MP-ALIPAY
			statusBarHeight = windowInfo.statusBarHeight
			// 注意：titleBarHeight 在 windowInfo 中可能不存在，需要适配
			const titleBarHeight = windowInfo.titleBarHeight || 0
			customBarHeight = windowInfo.statusBarHeight + titleBarHeight
			// #endif

			resolve({
				statusBarHeight,
				customBarHeight
			})
		} catch (err) {
			console.log("获取设备信息失败", err);
			reject(err)
		}
	})
}

export default updateCustomBarInfo